Chapter 17 - Local Values
Use some local values in order to define your infrastructure in one file. Use the DRY principle. Local values assist with repetition Don't overuse these as it makes the code hard to read by future maintainers
locals {
# Shorten the names for more readability
rg_name = "${var.business_unit}-${var.environment}-${var.resoure_group_name}"
vnet_name = "${var.business_unit}-${var.environment}-${var.virtual_network_name}"
# Common tags to be assigned to all resources
service_name = "MyServiceName"
common_tags = {
Service = local.service_name
Owner = local.owner
}
# Fixes this:
resource "azurerm_resource_group" "myrg" {
#name = "${var.business_unit}-${var.environment}-${var.resoure_group_name}"
name = local.rg_name
location = var.resoure_group_location
tags = local.common_tags
}